# -*- coding: utf-8 -*-  
#traform the data
'''
Created on Jan 13, 2015

@author: allenyang
'''
import types

class DataT:
    '''
    transform the type of the data
    '''
    def __init__(self,data):
        '''
        init the class
        '''
        self.data = data
        
        if type(data) is types.StringType:
            self.str = self.__str_rpl(data)
            if "," in self.str:
                self.list = self.__str_list(self.str)
            else:
                self.list = []
        elif type(data) is types.ListType:
            self.list = data

            
    def __str_rpl(self,string):
        '''
        escape "<>"
        '''
        return string.replace("<","&lt;").replace(">","&gt;")
            
    def __str_br(self,string):
        '''
        add "<br>" behind the string
        '''
        return string + "<br>"
    
    def __str_list(self,string):
        '''
        split the string
        for example:"123,435" to ["123","435"]
        '''
        return string.split(",")
    
    def __define_type(self,string):
        '''
        type
        '''
        if string == "c":
            return "Change"
        elif string == "a":
            return "Add"
        elif string == "d":
            return "Deleted"
        else:
            return string
    
    def data_transform(self):
        result = ""
        
        if self.list:
            for line in self.list:
                result += self.__str_br(self.__str_rpl(line))
            return result
        else:
            return self.__define_type(self.data) if self.data else "------"
            
if __name__ == "__main__":
    print DataT("1234,2323").data_transform()  
    
        
            
            